const {
	editMethod,
	cancelMethod,
	quickSaveMethod,
	saveMethod,
	showSaveDialogMethod,
} = require('./api-button-methods-2x')
const {
	saveJSONMethod,
} = require('./api-parameter-methods')
const {
	dialogClose,
} = require('./api-utils')

/**
 * 初始化编辑按钮
 * @param  {[type]} apiComp [description]
 * @return {[type]}         [description]
 */
module.exports = function initBtn(apiComp) {
	let {
		btnEdit,
		btnCancel,
		btnSave,
		btnQuickSave,
		jsonDialog,
		jsonText,
		saveDialog,
		saveFormVersion,
		saveFormIntro,
	} = apiComp;
	// 编辑按钮
	btnEdit.linkbutton({
		width: '80px',
		iconCls: 'icon-edit',
		text: '编辑',
		onClick() {
			editMethod.call(apiComp)
		},
	});
	// 取消按钮
	btnCancel.linkbutton({
		width: "80px",
		iconCls: 'icon-cancel',
		text: '取消',
		disabled: true,
		onClick() {
			cancelMethod.call(apiComp)
		},
	});
	// 快存按钮
	btnQuickSave.linkbutton({
		width: "80px",
		iconCls: 'icon-tip',
		text: '快存',
		disabled: true,
		onClick() {
			quickSaveMethod.call(apiComp)
		},
	});
	// 存储按钮
	btnSave.linkbutton({
		width: "80px",
		iconCls: 'icon-save',
		text: '保存',
		disabled: true,
		onClick() {
			showSaveDialogMethod.call(apiComp)
		},
	});

	// 导入JSON数据对话框
	jsonDialog.dialog({
		title: 'JSON导入',
		top: 100,
		left: 300,
		width: 800,
		height: 460,
		closed: true,
		modal: true,
		buttons: [{
			text: '保存',
			iconCls: 'icon-save',
			handler: function() {
				saveJSONMethod.call(apiComp)
			}
		}, {
			text: '取消',
			iconCls: 'icon-cancel',
			handler: function() {
				jsonDialog.dialog('close')
			}
		}],
		onClose() {
			dialogClose.call(apiComp)
		},
	});
	jsonText.textbox({
		multiline: true,
	});
	// 保存信息对话框
	saveDialog.dialog({
		title: '保存信息',
		top: 200,
		left: 400,
		width: 600,
		height: 320,
		closed: true,
		modal: true,
		buttons: [{
			text: '保存',
			iconCls: 'icon-save',
			handler: function() {
				saveMethod.call(apiComp)
			}
		}, {
			text: '取消',
			iconCls: 'icon-cancel',
			handler: function() {
				saveDialog.dialog('close')
			}
		}],
		onClose() {
			dialogClose.call(apiComp)
		},
	});
	saveFormVersion.combobox({
		label: '版本号:',
		editable: false,
		valueField: 'value',
		textField: 'text',
	});
	saveFormIntro.textbox({
		label: '描述:',
		multiline: true,
		required: true,
	})
}